<template>
    <div class="dashboard">
      <!-- <div class="top">
        <h1>首页</h1>
      </div> -->
      <div class="content" ref="chartDom">
  
      </div>
  
    </div>
  </template>
  
  <script setup>
  import { ref, onMounted,onBeforeUnmount } from 'vue'
  import * as echarts from 'echarts';
  
  const chartDom = ref(null)
  let myChart = null;
  const draw = () => {
    myChart = echarts.init(chartDom.value);
    const option = {
      title: {
        text: '订单统计'
      },
      tooltip: {
        trigger: 'axis'
      },
      legend: {
        data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      toolbox: {
        feature: {
          saveAsImage: {}
        }
      },
      xAxis: {
        type: 'category',
        boundaryGap: false,
        data: ['星期一', '星期二', '星期四', '星期四', '星期五', '星期六', '星期天']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          name: 'Email',
          type: 'line',
          stack: 'Total',
          clore: 'deepskyblue',
          data: [120, 132, 101, 134, 90, 230, 210]
        },
        {
          name: 'Union Ads',
          type: 'line',
          stack: 'Total',
          data: [220, 182, 191, 234, 290, 330, 310]
        },
        {
          name: 'Video Ads',
          type: 'line',
          stack: 'Total',
          data: [150, 232, 201, 154, 190, 330, 410]
        },
        {
          name: 'Direct',
          type: 'line',
          stack: 'Total',
          data: [320, 332, 301, 334, 390, 330, 320]
        },
        {
          name: 'Search Engine',
          type: 'line',
          stack: 'Total',
          data: [820, 932, 901, 934, 1290, 1330, 1320]
        }
      ]
    }
    myChart.setOption(option);
  };
  
  onMounted(() => {
    draw();
  });
  
  const handleResize = () => {
    console.log('窗口大小改变');
    myChart.resize();
  }
  
  
  window.addEventListener('resize', handleResize);{
    onBeforeUnmount(() => {
      window.removeEventListener('resize', handleResize); 
    })
  }
  
  </script>
  
  <style scoped>
  .dashboard {
    /* padding: 20px; */
    width: 100%;
    height: 100%;
    /* display: flex; */
    background-color: #fff;
    border-radius: 6px;
  }
  
  .dashboard-content {
    margin-top: 20px;
  }
  
  .top {
    width: 100%;
    height: 6%;
    font-size: 18px;
    /* font-weight: bold; */
    border-bottom: 1px solid #888787;
  }
  
  .top h1 {
    margin-left: 20px;
    line-height: 40px;
  }
  
  .content {
    /* margin-top: 20px; */
    width: 100%;
    height: 96%;
  }
  </style>